public class Test {


    public ListNode middleNode(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;

        if(head == null) {
            return null;
        }

        while(fast.next == null || fast == null) {
            slow = slow.next;
            fast = slow.next.next;
        }
        return slow;
    }


    public int kthToLast(int k) {
        if(k <= 0 || k > len) {
            return -1;
        }

        if(head == null) {
            return -1;
        }

        ListNode fast = head;
        ListNode slow = head;

        int index = k-1;
        while(index != 0) {
            fast = fast.next;
            index--;
        }

        while(fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow.val;

    }


    public ListNode reverseList() {
            ListNode cur = head;

        while (cur != null) {
            curNext = cur.next;

            cur.next = head;
            head = cur;
            cur = cur.next;
        }
    }
}

//    ListNode cur = head;
//    ListNode prev = null;
//
//    while (cur!= null) {
//            ListNode curNext = cur.next;
//            cur.next = prev;
//            prev = cur;
//            cur = curNext;
//            }
//            head = prev;
//            return head;
//